#!/usr/bin/env python3

import os
import subprocess
import sys

import common

def main():
    cmd = [
        os.path.join(common.qemu_src_dir, 'scripts/simpletrace.py'),
        os.path.join(common.qemu_build_dir, 'trace-events-all'),
        os.path.join(common.qemu_trace_file),
    ]
    return common.run_cmd(
        cmd,
        cmd_file=os.path.join(common.run_dir, 'qemu-trace2txt'),
        out_file=common.qemu_trace_txt_file,
        show_stdout=False,
    )

if __name__ == '__main__':
    parser = common.get_argparse(argparse_args={
        'description': 'Convert a QEMU `-trace exec_tb` to text form.'
    })
    args = common.setup(parser)
    sys.exit(main())
